﻿using Microsoft.AspNetCore.Authorization;
using Simple.Services.System.Conversation;
using Simple.Services.System.Dictionary.Models;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 家长/教师会话
    /// </summary>
    [Route("api/Conversation/[action]")]
    [ApiController]
    [Authorize]
    public class ConversationController
    {
        private readonly ConversationService _conversationService;
        public ConversationController(ConversationService conversationService)
        {
            _conversationService = conversationService;
        }

        /// <summary>
        /// 会话列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> List()
        {
            var data = await _conversationService.List();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 会话历史
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> History(Guid? conversationId)
        {
            var data = await _conversationService.GetMessageHistory(conversationId);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Send(SendConversationModel model)
        {
            var data = await _conversationService.SendMessage(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 删除会话
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete(string? conversationId)
        {
            var data = await _conversationService.Delete(conversationId);
            return AppResult.Status200OK(data: data);
        }
    }
}
